package br.org.isvi.interpretador.portugol.types;

import br.org.isvi.interpretador.portugol.exception.SemanticErrorException;

public class IntegerSymbol extends NumberSymbol {

	public IntegerSymbol(Integer value) {
		super(Kind.INTEIRO, value);
	}

	public static IntegerSymbol valueOf(String val) {
		IntegerSymbol ret = null;

		try {
			ret = new IntegerSymbol(Integer.parseInt(val));
		} catch (NumberFormatException e) {
			throw new SemanticErrorException(
					"Valor passado não é um numero inteiro válido!");
		}

		return ret;
	}

	@Override
	public String toString() {
		return getValue().toString();
	}

	public boolean bigger(Symbol symb) {

		int value = ((Integer) this.getValue()).intValue();
		double comp = 0;

		if (symb instanceof RealSymbol) {
			comp = ((Double) symb.getValue());
		} else {
			comp = ((Integer) symb.getValue());
		}

		return value > comp;
	}

	public boolean equals(Symbol symb) {

		int value = ((Integer) this.getValue()).intValue();
		double comp = 0;

		if (symb instanceof RealSymbol) {
			comp = ((Double) symb.getValue());
		} else {
			comp = ((Integer) symb.getValue());
		}

		return value == comp;
	}

	public boolean smaller(Symbol symb) {
		int value = ((Integer) this.getValue()).intValue();
		double comp = 0;

		if (symb instanceof RealSymbol) {
			comp = ((Double) symb.getValue());
		} else {
			comp = ((Integer) symb.getValue());
		}

		return value < comp;
	}
}
